/**
 * 2016，thor.com，all rights reserved。
 * 
 * Project：		palmmall-core
 * Filename：	SMeterInputConverter.java
 * Created：		2016年8月30日
 * Creator：		wolv
 */
package com.thor.palmmall.rest.patrol.converter;

import java.util.ArrayList;

import org.springframework.core.convert.converter.Converter;

import com.thor.commons.entity.KV;
import com.thor.commons.entity.UCN;
import com.thor.palmmall.rest.patrol.ADevice;
import com.thor.palmmall.rest.patrol.ADeviceState;
import com.thor.palmmall.spi.device.SDevice;

/**
 * @author wolv
 *
 */
public class ADeviceConverter implements Converter<SDevice, ADevice> {

  public static ADeviceConverter getInstance() {
    if (instance == null)
      instance = new ADeviceConverter();
    return instance;
  }

  private static ADeviceConverter instance;

  private ADeviceConverter() {
  }

  @Override
  public ADevice convert(SDevice source) {
    if (source == null)
      return null;

    ADevice target = new ADevice();
    target.setCategory(UCN.newInstance(source.getCategory()));
    target.setCode(source.getCode());
    // target.setCreateInfo();
    // target.setLastModifyInfo(lastModifyInfo);
    target.setName(source.getName());
    target.setPosition(source.getPosition());
    target.setProperties(new ArrayList<KV>());
    if (source.getProperties() != null)
      target.getProperties().addAll(source.getProperties());
    target.setRemark(source.getRemark());
    if (source.getState() != null)
      target.setState(ADeviceState.valueOf(source.getState().name()));
    target.setStore(UCN.newInstance(source.getStore()));
    target.setUuid(source.getUuid());
    target.setVersion(source.getVersion());

    return target;
  }

}
